package cevent.source.cloudcenter.server.service;

import cevent.source.cloudcenter.server.domain.Store;
import cevent.source.cloudcenter.server.domain.StoreExample;
import cevent.source.cloudcenter.server.dto.*;
import cevent.source.cloudcenter.server.enums.*;
import cevent.source.cloudcenter.server.listener.StoreExcelDtoListener;
import cevent.source.cloudcenter.server.mapper.StoreMapper;
import cevent.source.cloudcenter.server.util.DuplicateUtil;
import cevent.source.cloudcenter.server.util.UUID8Util;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author cevent
 * @description 店铺管理表服务层
 */
@Service
public class StoreService {
    private static final Logger LOG = LoggerFactory.getLogger(StoreService.class);
    @Resource
    private StoreMapper storeMapper;

    //1.无分页列表查询：dto获取domain参数
    public List<StoreDto> storeDtoList() {
        StoreExample storeExample = new StoreExample();
        storeExample.setOrderByClause("uni_id asc");
        List<Store> storeList = storeMapper.selectByExample(storeExample);
        List<StoreDto> storeDtoList = new ArrayList<StoreDto>();
        for (int i = 0; i < storeList.size(); i++) {
            Store store = storeList.get(i);
            StoreDto storeDto = new StoreDto();
            //复制拷贝(source,target)
            BeanUtils.copyProperties(store, storeDto);
            storeDtoList.add(storeDto);
        }
        return storeDtoList;
    }

    /*2.分页查询：pageDto保存数据
        list数据集合：listPageData
        当前页码：currentPage
        每页行数：size
        总计函数：totalSize
        前端可返回pageDto，无需返回值
     */
    public void getStorePageDtoList(PageDto pageDto) {
        //1.分页设置（前端传入当前页和每页行数params），起始页，每页行数size
        PageHelper.startPage(pageDto.getCurrentPage(), pageDto.getSize());
        StoreExample storeExample = new StoreExample();
        List<Store> storeList = storeMapper.selectByExampleWithBLOBs(storeExample);
        //2.将mapper查询结果复制到pageInfo
        PageInfo<Store> pageInfo = new PageInfo<>(storeList);
        //3.pageInfo计算处理处理=>后分页的总行数set到pageDto做记录
        pageDto.setTotalSize(pageInfo.getTotal());

        List<StoreDto> storeDtoList = new ArrayList<>();
        storeList.stream().forEach(store -> {
            JSONObject p = JSONObject.parseObject(store.getProvince());
            StoreProvinceDto province = JSONObject.toJavaObject(p, StoreProvinceDto.class);
            JSONObject c = JSONObject.parseObject(store.getCity());
            StoreCityDto city = JSONObject.toJavaObject(c, StoreCityDto.class);
            JSONObject d = JSONObject.parseObject(store.getDistrict());
            StoreDistrictDto district = JSONObject.toJavaObject(d, StoreDistrictDto.class);
            List<String> picList = new ArrayList<>();
            List<String> storeFront = new ArrayList<>();
            LOG.info("获取到的picList：{}", store.getPicList());
            if (!StringUtils.isEmpty(store.getPicList())) {
                picList = Arrays.asList(store.getPicList().split(";"));
            }
            if (!StringUtils.isEmpty(store.getStoreFront())) {
                storeFront = Arrays.asList(store.getStoreFront().split(";"));
            }
            StoreDto storeDto = new StoreDto();
            BeanUtils.copyProperties(store, storeDto);
            storeDto.setProvince(province);
            storeDto.setCity(city);
            storeDto.setDistrict(district);
            storeDto.setPicList(picList);
            storeDto.setStoreFront(storeFront);
            LOG.info("获取到的storeDto：{}", storeDto);
            storeDtoList.add(storeDto);
        });
        pageDto.setListPageData(storeDtoList);

    }

    //3.新增、修改store，将传入的id转为store对象本身
    public void save(StoreDto storeDto) {
        String province = null;
        String city = null;
        String district = null;
        if (storeDto.getProvince() != null) {
            //jsonObj转
            JSONObject jsonObject = (JSONObject) JSONObject.toJSON(storeDto.getProvince());
            //转jsonStr
            province = jsonObject.toString();
        }
        if (storeDto.getCity() != null) {
            JSONObject jsonObject = (JSONObject) JSONObject.toJSON(storeDto.getCity());
            city = jsonObject.toString();
        }
        if (storeDto.getDistrict() != null) {
            JSONObject jsonObject = (JSONObject) JSONObject.toJSON(storeDto.getDistrict());
            district = jsonObject.toString();
        }
        Store store = DuplicateUtil.copy(storeDto, Store.class);
        List<String> picList = new ArrayList<>();
        List<String> storeFront = new ArrayList<>();
        StringBuilder pics = new StringBuilder();
        StringBuilder fronts = new StringBuilder();
        if (storeDto.getPicList() != null) {
            picList = storeDto.getPicList();
            for (String pic : picList) {
                pics.append(pic + ";");
            }
        }
        String pic = pics.toString();

        if (storeDto.getStoreFront() != null) {
            storeFront = storeDto.getStoreFront();
            for (String front : storeFront) {
                fronts.append(front + ";");
            }
        }
        String front = fronts.toString();
        store.setProvince(province);
        store.setCity(city);
        store.setDistrict(district);
        store.setPicList(pic);
        store.setStoreFront(front);
        if (StringUtils.isEmpty(storeDto.getUniId())) {
            this.insert(store);
        } else {
            this.update(store);
        }

    }

    //4.删除模块
    public void delete(String uniId) {
        StoreExample storeExample = new StoreExample();
        storeMapper.deleteByPrimaryKey(uniId);
    }

    //5.向外暴露dto，不暴露实体类：插入数据
    private void insert(Store store) {
        store.setUniId(UUID8Util.getShortUUID());
        if (store.getTypeId() == null) {
            store.setTypeId(ModuleTypeEnum.BASE_MODULE.getCode());
        }

        try {
            Date now = new Date();
            String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);
            long time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date).getTime();
            int timeInt = (int) (time / 1000);
            store.setCreateTime(now);
            store.setUpdateTime(now);
        /*store.setiCreateTime(timeInt);
        store.setiUpdateTime(timeInt);*/
        } catch (ParseException e) {
            e.printStackTrace();
        }
        storeMapper.insertSelective(store);
    }

    //6.更新模块
    private void update(Store store) {
        try {
            Date now = new Date();
            String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);
            long time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date).getTime();
            int timeInt = (int) (time / 1000);

            store.setUpdateTime(now);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        storeMapper.updateByPrimaryKeySelective(store);
    }

    //支付凭证上传
    public List<String> savePicList(ModulePicPathDto modulePicPathDto) {
        Store store = storeMapper.selectByPrimaryKey(modulePicPathDto.getModuleId());
        List<String> picList = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        if (!StringUtils.isEmpty(store.getPicList())) {
            picList = Arrays.asList(store.getPicList().split(";"));
            for (String pic : picList) {
                sb.append(pic + ";");
            }
        }
        sb.append(modulePicPathDto.getPicPath() + ";");
        String pics = sb.toString();
        store.setPicList(pics);
        storeMapper.updateByPrimaryKeyWithBLOBs(store);
        List<String> miniPicList = getPicList(modulePicPathDto.getModuleId());
        return miniPicList;
    }

    private List<String> getPicList(String moduleId) {
        Store store = storeMapper.selectByPrimaryKey(moduleId);
        List<String> picList = Arrays.asList(store.getPicList().split(";"));
        return picList;
    }

    //门头图片上传
    public List<String> saveStoreFront(ModulePicPathDto modulePicPathDto) {
        Store store = storeMapper.selectByPrimaryKey(modulePicPathDto.getModuleId());
        List<String> storeFront = new ArrayList<>();
        StringBuilder stringBuilder = new StringBuilder();
        if (!StringUtils.isEmpty(store.getStoreFront())) {
            storeFront = Arrays.asList(store.getStoreFront().split(";"));
            for (String pic : storeFront) {
                stringBuilder.append(pic + ";");
            }
        }
        stringBuilder.append(modulePicPathDto.getPicPath() + ";");
        String front = stringBuilder.toString();
        store.setStoreFront(front);
        storeMapper.updateByPrimaryKeyWithBLOBs(store);
        List<String> storeFrontList = getStoreFront(modulePicPathDto.getModuleId());
        return storeFrontList;
    }

    private List<String> getStoreFront(String moduleId) {
        Store store = storeMapper.selectByPrimaryKey(moduleId);
        List<String> storeFront = Arrays.asList(store.getStoreFront().split(";"));
        return storeFront;
    }

    //1.根据省份查询
    public void getProvincePage(PageSelectDto pageSelectDto) {
        //1.分页设置
        PageHelper.startPage(pageSelectDto.getCurrentPage(), pageSelectDto.getSize());
        StoreExample storeExample = new StoreExample();
        StoreExample.Criteria criteria = storeExample.createCriteria();
        criteria.andProvinceLike("%"+pageSelectDto.getProvinceName()+"%");
        LOG.info("模糊查询条件：{}",criteria);
        List<Store> storeList = storeMapper.selectByExample(storeExample);
        LOG.info("查询到的storeDto：{}",storeList);
        //2.将storeList复制到pageInfo
        PageInfo<Store> storePageInfo = new PageInfo<>(storeList);
        pageSelectDto.setTotalSize(storePageInfo.getTotal());
        //3.storeDto转换
        List<StoreDto> storeDtoList = new ArrayList<>();
        storeList.stream().forEach(store -> {
            JSONObject p = JSONObject.parseObject(store.getProvince());
            StoreProvinceDto province = JSONObject.toJavaObject(p, StoreProvinceDto.class);
            JSONObject c = JSONObject.parseObject(store.getCity());
            StoreCityDto city = JSONObject.toJavaObject(c, StoreCityDto.class);
            JSONObject d = JSONObject.parseObject(store.getDistrict());
            StoreDistrictDto district = JSONObject.toJavaObject(d, StoreDistrictDto.class);
            List<String> picList = new ArrayList<>();
            List<String> storeFront = new ArrayList<>();
            LOG.info("获取到的picList：{}", store.getPicList());
            if (!StringUtils.isEmpty(store.getPicList())) {
                picList = Arrays.asList(store.getPicList().split(";"));
            }
            if (!StringUtils.isEmpty(store.getStoreFront())) {
                storeFront = Arrays.asList(store.getStoreFront().split(";"));
            }
            StoreDto storeDto = new StoreDto();
            BeanUtils.copyProperties(store, storeDto);
            storeDto.setProvince(province);
            storeDto.setCity(city);
            storeDto.setDistrict(district);
            storeDto.setPicList(picList);
            storeDto.setStoreFront(storeFront);
            LOG.info("获取到的storeDto：{}", storeDto);
            storeDtoList.add(storeDto);
        });
        pageSelectDto.setListPageData(storeDtoList);
    }

    //2.根据城市模糊查询
    public void getCityPage(PageSelectDto pageSelectDto) {
        //1.分页设置
        PageHelper.startPage(pageSelectDto.getCurrentPage(), pageSelectDto.getSize());
        StoreExample storeExample = new StoreExample();
        StoreExample.Criteria criteria = storeExample.createCriteria();
        criteria.andCityLike("%"+pageSelectDto.getCityName()+"%");
        LOG.info("模糊查询条件：{}",criteria);
        List<Store> storeList = storeMapper.selectByExample(storeExample);
        LOG.info("查询到的storeDto：{}",storeList);
        //2.将storeList复制到pageInfo
        PageInfo<Store> storePageInfo = new PageInfo<>(storeList);
        pageSelectDto.setTotalSize(storePageInfo.getTotal());
        //3.storeDto转换
        List<StoreDto> storeDtoList = new ArrayList<>();
        storeList.stream().forEach(store -> {
            JSONObject p = JSONObject.parseObject(store.getProvince());
            StoreProvinceDto province = JSONObject.toJavaObject(p, StoreProvinceDto.class);
            JSONObject c = JSONObject.parseObject(store.getCity());
            StoreCityDto city = JSONObject.toJavaObject(c, StoreCityDto.class);
            JSONObject d = JSONObject.parseObject(store.getDistrict());
            StoreDistrictDto district = JSONObject.toJavaObject(d, StoreDistrictDto.class);
            List<String> picList = new ArrayList<>();
            List<String> storeFront = new ArrayList<>();
            LOG.info("获取到的picList：{}", store.getPicList());
            if (!StringUtils.isEmpty(store.getPicList())) {
                picList = Arrays.asList(store.getPicList().split(";"));
            }
            if (!StringUtils.isEmpty(store.getStoreFront())) {
                storeFront = Arrays.asList(store.getStoreFront().split(";"));
            }
            StoreDto storeDto = new StoreDto();
            BeanUtils.copyProperties(store, storeDto);
            storeDto.setProvince(province);
            storeDto.setCity(city);
            storeDto.setDistrict(district);
            storeDto.setPicList(picList);
            storeDto.setStoreFront(storeFront);
            LOG.info("获取到的storeDto：{}", storeDto);
            storeDtoList.add(storeDto);
        });
        pageSelectDto.setListPageData(storeDtoList);
    }
    //3.根据支付状态查询
    public void getPayStatusPage(PageSelectDto pageSelectDto) {
        //1.分页设置
        PageHelper.startPage(pageSelectDto.getCurrentPage(), pageSelectDto.getSize());
        StoreExample storeExample = new StoreExample();
        StoreExample.Criteria criteria = storeExample.createCriteria();
        criteria.andPayStatusEqualTo(pageSelectDto.getPayStatus());
        LOG.info("模糊查询条件：{}",criteria);
        List<Store> storeList = storeMapper.selectByExample(storeExample);
        LOG.info("查询到的storeDto：{}",storeList);
        //2.将storeList复制到pageInfo
        PageInfo<Store> storePageInfo = new PageInfo<>(storeList);
        pageSelectDto.setTotalSize(storePageInfo.getTotal());
        //3.storeDto转换
        List<StoreDto> storeDtoList = new ArrayList<>();
        storeList.stream().forEach(store -> {
            JSONObject p = JSONObject.parseObject(store.getProvince());
            StoreProvinceDto province = JSONObject.toJavaObject(p, StoreProvinceDto.class);
            JSONObject c = JSONObject.parseObject(store.getCity());
            StoreCityDto city = JSONObject.toJavaObject(c, StoreCityDto.class);
            JSONObject d = JSONObject.parseObject(store.getDistrict());
            StoreDistrictDto district = JSONObject.toJavaObject(d, StoreDistrictDto.class);
            List<String> picList = new ArrayList<>();
            List<String> storeFront = new ArrayList<>();
            LOG.info("获取到的picList：{}", store.getPicList());
            if (!StringUtils.isEmpty(store.getPicList())) {
                picList = Arrays.asList(store.getPicList().split(";"));
            }
            if (!StringUtils.isEmpty(store.getStoreFront())) {
                storeFront = Arrays.asList(store.getStoreFront().split(";"));
            }
            StoreDto storeDto = new StoreDto();
            BeanUtils.copyProperties(store, storeDto);
            storeDto.setProvince(province);
            storeDto.setCity(city);
            storeDto.setDistrict(district);
            storeDto.setPicList(picList);
            storeDto.setStoreFront(storeFront);
            LOG.info("获取到的storeDto：{}", storeDto);
            storeDtoList.add(storeDto);
        });
        pageSelectDto.setListPageData(storeDtoList);
    }
    //4.根据门头达标状态查询
    public void getStoreFrontTypePage(PageSelectDto pageSelectDto) {
        //1.分页设置
        PageHelper.startPage(pageSelectDto.getCurrentPage(), pageSelectDto.getSize());
        StoreExample storeExample = new StoreExample();
        StoreExample.Criteria criteria = storeExample.createCriteria();
        criteria.andStoreFrontTypeEqualTo(pageSelectDto.getStoreFrontType());
        LOG.info("模糊查询条件：{}",criteria);
        List<Store> storeList = storeMapper.selectByExample(storeExample);
        LOG.info("查询到的storeDto：{}",storeList);
        //2.将storeList复制到pageInfo
        PageInfo<Store> storePageInfo = new PageInfo<>(storeList);
        pageSelectDto.setTotalSize(storePageInfo.getTotal());
        //3.storeDto转换
        List<StoreDto> storeDtoList = new ArrayList<>();
        storeList.stream().forEach(store -> {
            JSONObject p = JSONObject.parseObject(store.getProvince());
            StoreProvinceDto province = JSONObject.toJavaObject(p, StoreProvinceDto.class);
            JSONObject c = JSONObject.parseObject(store.getCity());
            StoreCityDto city = JSONObject.toJavaObject(c, StoreCityDto.class);
            JSONObject d = JSONObject.parseObject(store.getDistrict());
            StoreDistrictDto district = JSONObject.toJavaObject(d, StoreDistrictDto.class);
            List<String> picList = new ArrayList<>();
            List<String> storeFront = new ArrayList<>();
            LOG.info("获取到的picList：{}", store.getPicList());
            if (!StringUtils.isEmpty(store.getPicList())) {
                picList = Arrays.asList(store.getPicList().split(";"));
            }
            if (!StringUtils.isEmpty(store.getStoreFront())) {
                storeFront = Arrays.asList(store.getStoreFront().split(";"));
            }
            StoreDto storeDto = new StoreDto();
            BeanUtils.copyProperties(store, storeDto);
            storeDto.setProvince(province);
            storeDto.setCity(city);
            storeDto.setDistrict(district);
            storeDto.setPicList(picList);
            storeDto.setStoreFront(storeFront);
            LOG.info("获取到的storeDto：{}", storeDto);
            storeDtoList.add(storeDto);
        });
        pageSelectDto.setListPageData(storeDtoList);
    }
    //5.根据店铺类型查询
    public void getStoreTypePage(PageSelectDto pageSelectDto) {
        //1.分页设置
        PageHelper.startPage(pageSelectDto.getCurrentPage(), pageSelectDto.getSize());
        StoreExample storeExample = new StoreExample();
        StoreExample.Criteria criteria = storeExample.createCriteria();
        criteria.andTypeIdEqualTo(Integer.parseInt(pageSelectDto.getStoreType()));
        LOG.info("模糊查询条件：{}",criteria);
        List<Store> storeList = storeMapper.selectByExample(storeExample);
        LOG.info("查询到的storeDto：{}",storeList);
        //2.将storeList复制到pageInfo
        PageInfo<Store> storePageInfo = new PageInfo<>(storeList);
        pageSelectDto.setTotalSize(storePageInfo.getTotal());
        //3.storeDto转换
        List<StoreDto> storeDtoList = new ArrayList<>();
        storeList.stream().forEach(store -> {
            JSONObject p = JSONObject.parseObject(store.getProvince());
            StoreProvinceDto province = JSONObject.toJavaObject(p, StoreProvinceDto.class);
            JSONObject c = JSONObject.parseObject(store.getCity());
            StoreCityDto city = JSONObject.toJavaObject(c, StoreCityDto.class);
            JSONObject d = JSONObject.parseObject(store.getDistrict());
            StoreDistrictDto district = JSONObject.toJavaObject(d, StoreDistrictDto.class);
            List<String> picList = new ArrayList<>();
            List<String> storeFront = new ArrayList<>();
            LOG.info("获取到的picList：{}", store.getPicList());
            if (!StringUtils.isEmpty(store.getPicList())) {
                picList = Arrays.asList(store.getPicList().split(";"));
            }
            if (!StringUtils.isEmpty(store.getStoreFront())) {
                storeFront = Arrays.asList(store.getStoreFront().split(";"));
            }
            StoreDto storeDto = new StoreDto();
            BeanUtils.copyProperties(store, storeDto);
            storeDto.setProvince(province);
            storeDto.setCity(city);
            storeDto.setDistrict(district);
            storeDto.setPicList(picList);
            storeDto.setStoreFront(storeFront);
            LOG.info("获取到的storeDto：{}", storeDto);
            storeDtoList.add(storeDto);
        });
        pageSelectDto.setListPageData(storeDtoList);
    }

    //导出excel
    public void exportStoreExcel(HttpServletResponse httpServletResponse){
        //设置导出内容类型
        httpServletResponse.setContentType("application/vnd.ms-excel");
        //设置导出内容编码
        httpServletResponse.setCharacterEncoding("utf-8");
        //设置导出文件名,Content-disposition: attachment;filename=??????.xlsx 这里需要URL编码
        String excelName= null;
        try {
            excelName = java.net.URLEncoder.encode("亚盟门店信息表","utf-8");
        } catch (UnsupportedEncodingException e) {
            LOG.error("URL编码解析错误");
            e.printStackTrace();
        }
        //声明以下载方式打开：Content-disposition
        httpServletResponse.setHeader("Access-Control-Expose-Headers","Content-disposition");
        httpServletResponse.setHeader("Content-disposition","attachment;filename="+ excelName + ".xlsx");

        //获取导出数据
        StoreExample storeExample=new StoreExample();
        StoreExample.Criteria criteria=storeExample.createCriteria();
        storeExample.setOrderByClause("create_time desc");
        List<Store> storeList=storeMapper.selectByExampleWithBLOBs(storeExample);
        List<StoreExcelDto> storeExcelDtoList=new ArrayList<>();
        //遍历转存
        for(int i=0;i<storeList.size();i++){
            StoreExcelDto storeExcelDto=new StoreExcelDto();
            String province=storeList.get(i).getProvince();
            String p="";
            if(!StringUtils.isEmpty(province)){
                p= province.substring(province.indexOf("{\"add\":\"")+8,province.lastIndexOf("\",\"id\""));
            }

            String city=storeList.get(i).getCity();
            String c="";
            if(!StringUtils.isEmpty(city)){
                c=city.substring(city.indexOf("{\"add\":\"")+8,city.lastIndexOf("\",\"id\""));
            }

            String district=storeList.get(i).getDistrict();
            String d="";
            if(!StringUtils.isEmpty(district)){
                d= district.substring(district.indexOf("{\"add\":\"")+8,district.lastIndexOf("\",\"id\""));
            }

            Integer typeId=storeList.get(i).getTypeId();
            String typeName="";
            if(typeId.equals(StoreTypeEnum.GOODS_STATION.getCode())){
                typeName=StoreTypeEnum.GOODS_STATION.getDesc();
            }else if(typeId.equals(StoreTypeEnum.LOGISTICS_STATION.getCode())){
                typeName=StoreTypeEnum.LOGISTICS_STATION.getDesc();
            }else if(typeId.equals(StoreTypeEnum.UNION_MERCHANT.getCode())){
                typeName=StoreTypeEnum.UNION_MERCHANT.getDesc();
            }else if(typeId.equals(StoreTypeEnum.FRANCHISEE_STORE.getCode())){
                typeName=StoreTypeEnum.FRANCHISEE_STORE.getDesc();
            }else{
                typeName="未选择";
            }
            String payStatus=storeList.get(i).getPayStatus();
            if(payStatus.equals(PayStatusEnum.FULL_PAY.getCode())){
                payStatus=PayStatusEnum.FULL_PAY.getDesc();
            }else if(payStatus.equals(PayStatusEnum.DEPOSIT_PAY.getCode())){
                payStatus=PayStatusEnum.DEPOSIT_PAY.getDesc();
            }else{
                payStatus="未选择";
            }
            String storeFrontType=storeList.get(i).getStoreFrontType();
            if(storeFrontType.equals(StoreFrontTypeEnum.PASS_ON.getCode())){
                storeFrontType=StoreFrontTypeEnum.PASS_ON.getDesc();
            }else if(storeFrontType.equals(StoreFrontTypeEnum.PASS_OFF.getCode())){
                storeFrontType=StoreFrontTypeEnum.PASS_OFF.getDesc();
            }else{
                storeFrontType="未上传门头";
            }
            String subsidyType=storeList.get(i).getSubsidyType();
            if(subsidyType.equals(SubsidyType.SUBSIDY_IN.getCode())){
                subsidyType=SubsidyType.SUBSIDY_IN.getDesc();
            }else{
                subsidyType=SubsidyType.SUBSIDY_UN.getDesc();
            }
            String storeStatus=storeList.get(i).getStoreStatus();
            if(storeStatus.equals(StoreStatusEnum.OPERATION_ARRANGE.getCode())){
                storeStatus=StoreStatusEnum.OPERATION_ARRANGE.getDesc();
            }else if(storeStatus.equals(StoreStatusEnum.OPERATION_ON.getCode())){
                storeStatus=StoreStatusEnum.OPERATION_ON.getDesc();
            }else if(storeStatus.equals(StoreStatusEnum.OPERATION_OFF.getCode())){
                storeStatus=StoreStatusEnum.OPERATION_OFF.getDesc();
            }else{
                storeStatus="未选择";
            }
            //日期转换
            SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date createTime=storeList.get(i).getCreateTime();

            String ct=dateFormat.format(createTime);
            Date updateTime=storeList.get(i).getUpdateTime();
            String ut=dateFormat.format(updateTime);
            BeanUtils.copyProperties(storeList.get(i),storeExcelDto);
            storeExcelDto.setOrderId(i+1);
            storeExcelDto.setProvince(p);
            storeExcelDto.setCity(c);
            storeExcelDto.setDistrict(d);
            storeExcelDto.setTypeId(typeName);
            storeExcelDto.setPayStatus(payStatus);
            storeExcelDto.setStoreFrontType(storeFrontType);
            storeExcelDto.setSubsidyType(subsidyType);
            storeExcelDto.setCreateTime(ct);
            storeExcelDto.setUpdateTime(ut);
            storeExcelDtoList.add(storeExcelDto);
        }
        LOG.info("获取到的excelDto：{}",storeExcelDtoList);
        //执行导出

        try {
            EasyExcel.write(httpServletResponse.getOutputStream(),StoreExcelDto.class)
                    .sheet("亚盟全国门店数据表 cevent提供技术支持").doWrite(storeExcelDtoList);
        } catch (IOException e) {
            LOG.error("导出数据失败");
            e.printStackTrace();
        }
            /*EasyExcel.write("D:\\myeclipse2017\\easyexcel_test2.xlsx",StoreExcelDto.class)
                    .sheet("亚盟全国门店数据表   --> Technology by cevent").doWrite(storeExcelDtoList);*/
    }

    //导入excel，生成数据
    public void importStoreExcel(MultipartFile file){
        //读取excel，输入流
        try {
            EasyExcel.read(file.getInputStream(),StoreExcelDto.class,new StoreExcelDtoListener(storeMapper)).sheet().doRead();
        } catch (IOException e) {
            LOG.error("读取input stream错误！");
            e.printStackTrace();
        }
    }
}
